<template>
  <div class="login-container">
    <div class="login-box">
      <div class="left">
        <img :src="LoginImg" />
        课件学习平台
      </div>
      <div class="right">
        <p>账号登录</p>
        <div class="form-box">
          <a-input
            v-model="formData.username"
            placeholder="请输入用户名"
            size="large"
          >
            <a-icon slot="prefix" type="user" />
          </a-input>
          <a-input
            v-model="formData.password"
            style="margin-top: 20px"
            type="password"
            placeholder="请输入密码"
            size="large"
          >
            <a-icon slot="prefix" type="lock" />
          </a-input>
          <a-button
            style="margin-top: 80px"
            type="primary"
            size="large"
            @click="handleLogin"
          >
            <span>登录</span>
          </a-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import LoginImg from '@/assets/img/login.png'
export default {
  name: 'Login',
  data() {
    return {
      LoginImg,
      formData: {
        username: '',
        password: ''
      }
    }
  },
  mounted() {
    this.createRound()
  },
  methods: {
    /**
     * 生成背景圆点效果
     */
    createRound() {
      for (let i = 0; i < 30; i++) {
        const round = document.createElement('div')
        round.classList.add('round')
        const colorList = ['#00b894', '#6c5ce7', '#ff7675']
        // 设置圆点位置
        round.style.top = `${Math.random() * (window.innerHeight - 100)}px`
        round.style.left = `${Math.random() * (window.innerWidth - 100)}px`
        // 设置圆点大小
        const height = Math.random() * 50 > 25 ? Math.random() * 50 : 25
        round.style.height = `${height}px`
        round.style.width = `${height}px`
        // 设置圆点颜色
        const index = parseInt(Math.random() * 3)
        round.style.backgroundColor = colorList[index]
        document.querySelector('.login-container').appendChild(round)
      }
    },
    handleLogin() {
      if (!this.formData.username || !this.formData.password) {
        this.$message.error('请输入用户名和密码')
      } else if (
        this.formData.username !== 'admin' &&
        this.formData.password !== '123456'
      ) {
        this.$message.error('请输入正确的用户名和密码')
      } else {
        this.$message.success('登录成功')
        this.$router.push('/layout/userManager')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.login-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  background-color: rgba(52, 152, 219, 0.2);
  display: flex;
  justify-content: center;
  align-items: center;
}
.login-box {
  box-sizing: border-box;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: 70%;
  width: 50%;
  background-color: rgba(255, 255, 255, 0.9);
  z-index: 2;
  box-shadow: 0 0 25px rgba(52, 152, 219, 0.6);
  border-top-left-radius: 40px;
  border-bottom-right-radius: 40px;
  border-top-right-radius: 10px;
  border-bottom-left-radius: 10px;
  display: flex;
  padding: 15px;
}
/deep/ .round {
  position: absolute;
  border-radius: 50%;
  height: 40px;
  width: 40px;
  opacity: 0.9;
  z-index: 1;
}
.left,
.right {
  height: 100%;
  width: 50%;
}
.left {
  background-color: rgba(52, 152, 219, 0.6);
  border-top-left-radius: 35px;
  border-bottom-right-radius: 35px;
  border-top-right-radius: 10px;
  border-bottom-left-radius: 10px;
  color: #fff;
  overflow: hidden;
  font-size: 35px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  letter-spacing: 4px;
  img {
    margin-top: -120px;
    width: 120px;
    height: 120px;
    margin-bottom: 10;
  }
}
.right {
  text-align: center;
  font-size: 30px;
  color: var(--primary-base);
  padding-top: 100px;
  .form-box {
    padding: 0 80px;
    margin-top: 60px;
  }
}
</style>